$(document).ready(function() {

	// cbs 
		em.cbs= {};
		
		// for cstl move & wave 
		em.cbs.cstlmove1done = $.Callbacks( "unique stopOnFalse" );	
		em.cbs.cstlwavedone = $.Callbacks( "unique stopOnFalse" );
		
			
		// login new user : got new key 
		em.cbs.userlogin = $.Callbacks("unique stopOnFalse");
		
		// when completed select new user : start GM  -> new login : get system task api :: then fire . :  reset all prev datas  
		em.cbs.userchanged = $.Callbacks("unique stopOnFalse");
			// when start user change :  to notify free prev resource  
		em.cbs.startuserchange = $.Callbacks("unique stopOnFalse");
		
		// all hero list update
		em.cbs.heroupdate = $.Callbacks("unique stopOnFalse");
		// hnting avaliable h list update 
		em.cbs.warableHpdate = $.Callbacks("unique stopOnFalse");
		
		// hnt  : 1 da hnt 1 time end cb  for cals end time : decide next ctsl
		em.cbs.hntdone = $.Callbacks("unique stopOnFalse");
		// 1 cstl att is done !!
		em.cbs.autoCstlAttDone = $.Callbacks("unique stopOnFalse");  
		// update cstl 's sols '
		em.cbs.updatesols = $.Callbacks("unique stopOnFalse");
		
		// sols trained finished  
		em.cbs.soltraindone = $.Callbacks("unique stopOnFalse");
		
		// global contorl cb 
		em.cbs.forcestop = $.Callbacks("unique stopOnFalse");
		
		// timer for desc time info  
		em.cbs.sectimer = $.Callbacks("unique stopOnFalse");
		
		
	// global 
		// var users = CDB.users;//[ 'james', 'greate'];
		// var devices = CDB.devices;//['iphone', 'android' ] ;
		
	em.cstlview = new CCstlView();
	em.cstlview.initialize();

	em.cstlmgr = new CCstlMgr();
	em.cstlmgr.cstlwave_initialize();
	em.cstlmgr.setView(em.cstlview);


	em.query = new CQuery();
	em.query.initialize();

	em.util = new CUtil();
		
	em.tasks = new CTasks();
	
	em.controller = new CController();
	
	em.infoview = new CInfoView();
	em.infoview.initialize();
	
	
	// start monotor !!
	em.jobmonitor.registerCBs();
	em.jobmonitor.startMonitor();
	/*
		panel...
	*/
	

	
	//======================= TEST code here ========================
	// set login defualt user 'Greateload' for test 
	// em.controller.login('Greateload');
		
	em.infoview.connected();
	
	console.log( $.now());

/*
  Edit: the next line does not work in some
  browsers but I'm leaving it here so the comments
  on the blog post make sense.
*/
MyObject = {};
if (typeof(MyObject) != "undefined") MyObject = {};
/**
 * Bind a callback to a custom event on MyObject
 */
$(MyObject).bind("main", function(event, theData) {
    alert(theData);
});
/**
 * Now trigger the custom event on the custom object
 */
// $(MyObject).trigger("main", "Welcome to the main event");


/*
	// test code !!
	// send result to UI Veiw
	em.cstlview.updateHDrin( 1,
		{
		"code":0,"ret":
		{"gold":24148,"price":5135,"refresh":3600,"hero":{"gid":117,"p":11,"i":21,"c1":15,"g":2,"c2":295},"rumor":0}
		});*/

	
	
	// set initial info
	if ( em.test ) {
		$('#mode_indicator').html($('<span>').text('TEST MODE!!')).show();
		$('#mode_indicator').click(function() {
			em.test = false;
			$(this).hide();
		});
	}
	

		/*
			 google panel 
		*/
		
		
		
	console.log( ' Try install Office screen... ');
	if ( em.place == 'office') {
			console.log( ' Cur is Office mode ');
		
		$('#navi_container').click( function(){
			console.log( ' google screend.. ');
			$('#google_screen').toggle();;
		});
	
		$('#google_screen').click( function(){
			console.log( ' google screend.. ');
			$('#google_screen').toggle();;
		});
	}


	$("#id_scrolldown").click( function(e) {
			$('#result_box').animate({scrollTop: $('#result_box')[0].scrollHeight});
	   });


	

   
});
  


